<script type="text/javascript">

$(document).ready(function(){

$("#btn-rate").click(function(){
var sum_insured = parseInt($("#sum_insured").val());
var rate = parseInt($("#rate").val());
var premi = sum_insured * (rate/100);
$("#premium").val(premi);
});


$("#value_brokerage").click("change",function(){
var value=$(this).val();
var adjusment = parseInt($("#adjusment").val());
var tpl = parseInt($("#tpl").val());

var premiAwal = parseInt($("#premium").val()) + parseInt(tpl);
var client_tahu_diskon = $("#client_tahu_diskon").val();
var diskonAgra = parseInt($("#discount").val());
var diskonAsuransi = parseInt($("#diskon_asuransi").val());

//if(client_tahu_diskon=="1"){
//	var diskon = 0;
//}
//else{
	var diskon = diskonAsuransi;
//}


if(value=="1"){
	$("#hasil-premi").text(premiAwal);
	$("#txt_hasil_premi").val(premiAwal);
}
else{
	$("#hasil-premi").text(premiAwal-diskon);
	$("#txt_hasil_premi").val(premiAwal-diskon);	
}

});


$("#brokerage_percent").keyup(function(){
var value = parseFloat($(this).val());
var premi = parseFloat($("#txt_hasil_premi").val());

var brokerage = (value/100)*premi;
$("#brokerage").val(brokerage);
});


$("#ppn_percent").keyup(function(){
var value = parseFloat($(this).val());
var brokerage = parseFloat($("#brokerage").val());

var ppn = (value/100)*brokerage;
$("#ppn").val(ppn);
});


$("#pph_percent").keyup(function(){
var value = parseFloat($(this).val());
var brokerage = parseFloat($("#brokerage").val());

var pph = (value/100)*brokerage;
$("#pph").val(pph);
});

});

</script>
<div class="form">

    <?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
	'id'=>'ndk-health-non-form',
	// Please note: When you enable ajax validation, make sure the corresponding
	// controller action is handling ajax validation correctly.
	// There is a call to performAjaxValidation() commented in generated controller code.
	// See class documentation of CActiveForm for details on this.
	'enableAjaxValidation'=>false,
)); ?>

    <p class="help-block">Fields with <span class="required">*</span> are required.</p>

    <?php echo $form->errorSummary($model); ?>
	<div class="row">
		<div class="col-md-4">
			<div class="widget box">
				<div class="widget-header">
				<h4><i class="icon-reorder"></i> Form Non Health </h4>
				</div>
				<div class="widget-content">
					<?php echo $form->textFieldControlGroup($model,'nota_debet_no',array('class'=>'form-control','maxlength'=>50, 'readOnly'=>true,'value'=>'Automatic Fill')); ?>
					
					<?php echo $form->textFieldControlGroup($model,'createdtime',array('class'=>'form-control','maxlength'=>50,'data-mask'=>'99-99-9999','value'=>date('d-m-Y'))); ?>

				<div class="control-group">
				<label class="control-label">
				Policy No
				<span class="required">*</span>
				</label>
				<div class="controls">
					<div class="input-group">
						<input id="policy_no" class="form-control input-width-large" type="text" name="policy_no">
						<a class="btn btn-default btn-warning" href="#myModal" data-toggle="modal" style="float:right">FIND</a>
					</div>
					<input type="hidden" name="NdkHealthNon[reg_nonhealth_policy_id]" id="reg_nonhealth_policy_id" />
					<input type="hidden" name="jml_installment" id="jml_installment" />
				</div>
				</div>
				
				<div class="control-group">
				<label class="control-label">
				Jenis Asuransi
				</label>
				<div class="controls">
					<span class="required" id="lbl_jenis_asuransi"></span>
				</div>
				</div>

					<?php echo $form->textFieldControlGroup($model,'endorsement_no',array('class'=>'form-control','maxlength'=>50)); ?>

					<?php //echo $form->textFieldControlGroup($model,'nominal',array('class'=>'form-control')); ?>

					<?php echo $form->textFieldControlGroup($model,'sum_insured',array('class'=>'form-control','id'=>'sum_insured', 'readonly'=>'readonly')); ?>

					<div class="control-group">
					<label class="control-label">
					Rate
					</label>
					<div class="controls">
						<div class="input-group">
							<input id="rate" class="form-control input-width-medium" type="text" name="NdkHealthNon[rate]" value="0">
							<a class="btn btn-default btn-warning" data-toggle="modal" style="float:right" id="btn-rate">Hitung</a>
						</div>
					</div>
					</div>

					<?php echo $form->textFieldControlGroup($model,'premium',array('class'=>'form-control', 'id'=>'premium')); ?>

					<?php echo $form->textFieldControlGroup($model,'policy_cost',array('class'=>'form-control', 'value'=>0)); ?>

					<?php echo $form->textFieldControlGroup($model,'tpl',array('class'=>'form-control','value'=>0, 'id'=>'tpl')); ?>


				</div>
			</div>
		</div>
		
		<div class="col-md-4">
			<div class="widget box">
				<div class="widget-header">
				<h4><i class="icon-reorder"></i> Form Non Health </h4>
				</div>
				<div class="widget-content">
					
					<?php echo $form->dropDownListControlGroup($model, 'type', array('NB' => 'New Business', 'EP' => 'Extra Premium', 'RN' => 'Renewal'), array('class'=>'form-control input-width-medium')); ?>

					<?php echo $form->textFieldControlGroup($model,'admin_broker',array('class'=>'form-control','value'=>0)); ?>

					<?php echo $form->textFieldControlGroup($model,'stamp_duty',array('class'=>'form-control','value'=>0)); ?>

					<?php echo $form->textFieldControlGroup($model,'stampduty_asuransi',array('class'=>'form-control','value'=>0)); ?>

					

					<div class="control-group">
					<label class="control-label" for="NdkHealthNon_ppn">Diskon Internal / Agra</label>
										<div class="controls">
											<div class="input-group">
												<?php echo $form->textField($model,'discount',array('class'=>'form-control input-width-large','id'=>'discount','value'=>0)); ?>
												<?php echo $form->hiddenField($model,'discount_percent',array('class'=>'form-control input-width-mini','style'=>'float:right', 'value'=>0)); ?>
											</div>
										</div>
					</div>

					<div class="control-group">
					<label class="control-label" for="NdkHealthNon_ppn">Diskon Asuransi</label>
										<div class="controls">
											<div class="input-group">
												<?php echo $form->textField($model,'diskon_asuransi',array('class'=>'form-control input-width-large','id'=>'diskon_asuransi','value'=>0)); ?>
												<?php echo $form->hiddenField($model,'diskon_asuransi_percent',array('class'=>'form-control input-width-mini','style'=>'float:right', 'value'=>0)); ?>
											</div>
										</div>
					</div>


					<?php echo $form->dropDownListControlGroup($model, 'client_tahu_diskon', array(1 => "Tidak", 2 => "Ya"),array('id'=>'client_tahu_diskon','class'=>'form-control input-width-large')); ?>

					
					<?php echo $form->textFieldControlGroup($model,'adjusment',array('class'=>'form-control','value'=>0,'id'=>'adjusment')); ?>
					
					<?php //echo $form->textFieldControlGroup($model,'total_premium',array('class'=>'form-control')); ?>
				</div>
			</div>
		</div>
		
		<div class="col-md-4">
			<div class="widget box">
				<div class="widget-header">
				<h4><i class="icon-reorder"></i> Form Non Health </h4>
				</div>
				<div class="widget-content">

					

					<div class="control-group">
					<label class="control-label">
					Due Date
					<span class="required">*</span>
					</label>
					<div class="controls">
					<div class="input-group">
					<input id="NdkHealth_due_date" class="form-control input-width-large" type="text" readonly="readonly" maxlength="50" name="NdkHealthNon[due_date]">
					<a class="btn btn-default btn-warning" id="btn_due_date" style="float:right" data-toggle="modal" href="#myModalDueDate">+</a>
					</div>
					</div>
					</div>

					<br />
					<?php echo $form->dropDownList($model, 'value_brokerage', array(1 => "Premi Awal", 2 => "Premi - Diskon"),array('prompt'=>'Pilih','id'=>'value_brokerage','class'=>'form-control input-width-medium')); ?>
												<br />
												<strong>Premi : <span id="hasil-premi"></span></strong>													
												<input type="hidden" name="txt_hasil_premi" id="txt_hasil_premi" />
												<br />

					<div class="control-group">
					<label class="control-label" for="NdkHealthNon_ppn">Brokerage</label>
										<div class="controls">
											<div class="input-group">
												<?php echo $form->textField($model,'brokerage',array('class'=>'form-control input-width-large','id'=>'brokerage')); ?>
												<?php echo $form->textField($model,'brokerage_percent',array('id'=>'brokerage_percent', 'class'=>'form-control input-width-mini','style'=>'float:right')); ?>
												<span class="input-group-addon">%</span>
											</div>
										</div>
					</div>
					
					
					<div class="control-group">
					<label class="control-label" for="NdkHealthNon_ppn">Ppn</label>
										<div class="controls">
											<div class="input-group">
												<?php echo $form->textField($model,'ppn',array('class'=>'form-control input-width-large', 'id'=>'ppn')); ?>
												<?php echo $form->textField($model,'ppn_percent',array('id'=>'ppn_percent','class'=>'form-control input-width-mini','style'=>'float:right')); ?>
												<span class="input-group-addon">%</span>
											</div>
										</div>
					</div>
					
					<div class="control-group">
					<label class="control-label" for="NdkHealthNon_ppn">Pph</label>
										<div class="controls">
											<div class="input-group">
												<?php echo $form->textField($model,'pph',array('class'=>'form-control input-width-large', 'id'=>'pph')); ?>
												<?php echo $form->textField($model,'pph_percent',array('id'=>'pph_percent', 'class'=>'form-control input-width-mini','style'=>'float:right')); ?>
												<span class="input-group-addon">%</span>
											</div>
										</div>
					</div>


					<?php echo $form->textAreaControlGroup($model,'note',array('class'=>'form-control','maxlength'=>100)); ?>
				</div>
			</div>
		</div>
		
	</div>
	
	<div class="row">
		
		<div class="col-md-12">
		  <div class="form-actions">
			<div class="form-actions">
			<?php echo TbHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',array(
				'color'=>TbHtml::BUTTON_COLOR_PRIMARY,
				'size'=>TbHtml::BUTTON_SIZE_LARGE,
			)); ?>
			</div>
		</div>
		</div>
	</div>
	
	<div id="myModal" class="modal fade in" style="display: none;" aria-hidden="false">
												<div class="modal-dialog" style="width:700px;">
													<div class="modal-content">
														<div class="modal-header">
															<button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
															<h4 class="modal-title">Pilih Client</h4>
														</div>
														<div class="modal-body">
															
															<?php echo $this->renderPartial('_viewClient', array('model'=>$model2));  // I need $productId to by dynamic related to link 
                ?> 
														</div>
														<div class="modal-footer">
															<button data-dismiss="modal" class="btn btn-default" type="button">Close</button>
															<button id="btnTest" data-dismiss="modal" class="btn btn-primary" type="button">Pilih</button>
														</div>
													</div><!-- /.modal-content -->
												</div><!-- /.modal-dialog -->
											</div>


	<div id="myModalDueDate" class="modal fade in" style="display: none;" aria-hidden="false">
												<div class="modal-dialog" style="width:700px;">
													<div class="modal-content">
														<div class="modal-header">
															<button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
															<h4 class="modal-title">Setting Due Date</h4>
														</div>
														<div class="modal-body">
															
															<?php echo $this->renderPartial('_duedate', array('model'=>$model3));  // I need $productId to by dynamic related to link 
                ?> 
														</div>
														<div class="modal-footer">
															<button id="btnPilihDueDate" data-dismiss="modal" class="btn btn-primary" type="button">Selesai</button>
														</div>
													</div><!-- /.modal-content -->
												</div><!-- /.modal-dialog -->
	</div>
											
    <?php $this->endWidget(); ?>

</div><!-- form -->

<script type="text/javascript">
$(document).ready(function(){


$("#btnTest").click(function()
{
   var nil = "";
    nil = $('input:radio[name=user]:checked').val();
   $("#policy_no").val(nil);
   $("#reg_nonhealth_policy_id").val($('input:radio[name=user]:checked').attr('id_number'));
   $("#sum_insured").val($('input:radio[name=user]:checked').attr('sum_insured'));
   $("#jml_installment").val($('input:radio[name=user]:checked').attr('jml_installment'));
   $("#lbl_jenis_asuransi").text($('input:radio[name=user]:checked').attr('jenis_asuransi'));
}); 


$("#btnPilihDueDate").click(function()
{
	
	var installment = $("#jml_installment").val();
	var html='';
	for(var i=1;i<=installment;i++){
	html += $("#input_due_date"+i).val()+'|';
	}
	var str = html.substr(0,html.length-1);
	$("#NdkHealth_due_date").val(str);
	
	});
}); 

</script>